//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "PositiveConstraint.h"
using namespace Cephei::QL::Math::Optimization;
#include <gen/QL/Math/Array.h>
#include <gen/QL/Math/Optimization/Constraint.h>
using namespace Cephei::QL::Math;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Optimization::CPositiveConstraint::CPositiveConstraint () : CConstraint(CPositiveConstraint::typeid)
{
    try
    {
#ifdef HANDLE
        _phPositiveConstraint = NULL;
#endif
        _ppPositiveConstraint = new boost::shared_ptr<QuantLib::PositiveConstraint> (new QuantLib::PositiveConstraint ( ));
        SetConstraint (boost::dynamic_pointer_cast<QuantLib::Constraint> (*_ppPositiveConstraint));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Optimization::CPositiveConstraint::CPositiveConstraint (boost::shared_ptr<QuantLib::PositiveConstraint>& childNative, Object^ owner) : CConstraint(CPositiveConstraint::typeid)
{
#ifdef HANDLE
	_phPositiveConstraint = NULL;
#endif
	_ppPositiveConstraint = &childNative;
    _ppConstraint = new boost::shared_ptr<QuantLib::Constraint> (boost::dynamic_pointer_cast<QuantLib::Constraint> (*_ppPositiveConstraint));
}
Cephei::QL::Math::Optimization::CPositiveConstraint::CPositiveConstraint (QuantLib::PositiveConstraint& childNative, Object^ owner) : CConstraint(CPositiveConstraint::typeid)
{
#ifdef HANDLE
	_phPositiveConstraint = NULL;
#endif
	_ppPositiveConstraint = new boost::shared_ptr<QuantLib::PositiveConstraint> (&childNative);
    _ppConstraint = new boost::shared_ptr<QuantLib::Constraint> (boost::dynamic_pointer_cast<QuantLib::Constraint> (*_ppPositiveConstraint));
    _PositiveConstraintOwner = owner;
    _ConstraintOwner = owner;
}

Cephei::QL::Math::Optimization::CPositiveConstraint::CPositiveConstraint (CPositiveConstraint^ copy) : CConstraint(CPositiveConstraint::typeid)
{
#ifdef HANDLE
	_phPositiveConstraint = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppPositiveConstraint = new boost::shared_ptr<QuantLib::PositiveConstraint> (copy->GetShared());
        _ppConstraint = new boost::shared_ptr<QuantLib::Constraint> (boost::dynamic_pointer_cast<QuantLib::Constraint> (*_ppPositiveConstraint));
    }
}
Cephei::QL::Math::Optimization::CPositiveConstraint::CPositiveConstraint (System::Type^ t) : CConstraint(CPositiveConstraint::typeid)
{
#ifdef HANDLE
	_phPositiveConstraint = NULL;
#endif
	if (!t->IsSubclassOf(CPositiveConstraint::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Optimization::CPositiveConstraint::CPositiveConstraint (QuantLib::Handle<QuantLib::PositiveConstraint>& childNative, Object^ owner)  : CConstraint(CPositiveConstraint::typeid)
{
	_phPositiveConstraint = &childNative;
	_ppPositiveConstraint = &static_cast<boost::shared_ptr<QuantLib::PositiveConstraint>>(childNative.currentLink());
    _ppConstraint = new boost::shared_ptr<QuantLib::Constraint> (boost::dynamic_pointer_cast<QuantLib::Constraint> (*_ppPositiveConstraint));
    _PositiveConstraintOwner = owner;
}
Cephei::QL::Math::Optimization::CPositiveConstraint::CPositiveConstraint (QuantLib::Handle<QuantLib::PositiveConstraint> childNative)  : CConstraint(CPositiveConstraint::typeid)
{
	_phPositiveConstraint = &childNative;
	_ppPositiveConstraint = &static_cast<boost::shared_ptr<QuantLib::PositiveConstraint>>(childNative.currentLink());
    _ppConstraint = new boost::shared_ptr<QuantLib::Constraint> (boost::dynamic_pointer_cast<QuantLib::Constraint> (*_ppPositiveConstraint));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Optimization::CPositiveConstraint::CPositiveConstraint (QuantLib::PositiveConstraint childNative)  : CConstraint(CPositiveConstraint::typeid)
{
#ifdef HANDLE
	_phPositiveConstraint = NULL;
#endif
	_ppPositiveConstraint = new boost::shared_ptr<QuantLib::PositiveConstraint> (new QuantLib::PositiveConstraint (childNative));
    _ppConstraint = new boost::shared_ptr<QuantLib::Constraint> (boost::dynamic_pointer_cast<QuantLib::Constraint> (*_ppPositiveConstraint));
}
#endif

Cephei::QL::Math::Optimization::CPositiveConstraint::~CPositiveConstraint ()
{
    if (_ppPositiveConstraint != NULL)
    {
	    delete _ppPositiveConstraint;
        _ppPositiveConstraint = NULL;
    }
}
Cephei::QL::Math::Optimization::CPositiveConstraint::!CPositiveConstraint ()
{
    if (_ppPositiveConstraint != NULL)
    {
	    delete _ppPositiveConstraint;
    }
}
QuantLib::PositiveConstraint& Cephei::QL::Math::Optimization::CPositiveConstraint::GetReference ()
{
    if (_ppPositiveConstraint == NULL) throw gcnew NativeNullException ();
	return **_ppPositiveConstraint;
}
boost::shared_ptr<QuantLib::PositiveConstraint>& Cephei::QL::Math::Optimization::CPositiveConstraint::GetShared ()
{
    if (_ppPositiveConstraint == NULL) throw gcnew NativeNullException ();
	return *_ppPositiveConstraint;
}
QuantLib::PositiveConstraint* Cephei::QL::Math::Optimization::CPositiveConstraint::GetPointer ()
{
    if (_ppPositiveConstraint == NULL) throw gcnew NativeNullException ();
	return &**_ppPositiveConstraint;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::PositiveConstraint>& Cephei::QL::Math::Optimization::CPositiveConstraint::GetHandle ()
{
	if (_phPositiveConstraint == NULL)
	{
		_phPositiveConstraint = new Handle<QuantLib::PositiveConstraint> (*_ppPositiveConstraint);
	}
	return *_phPositiveConstraint;
}
#endif
bool Cephei::QL::Math::Optimization::CPositiveConstraint::HasNative () 
{
	return (_ppPositiveConstraint != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Optimization::IPositiveConstraint^ Cephei::QL::Math::Optimization::CPositiveConstraint_Factory::Create ()
{
    return gcnew CPositiveConstraint ();
}
